﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WindowsFormsApplication1
{
   public class records
    {
        public class rec
        {
            public string Name;
            public int Score;
        }
        rec[] Players = new rec[10];

        public void Read_record()
        {
            FileStream fs = new FileStream("rec.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string temp_str = sr.ReadToEnd();
            string[] str = temp_str.Split(' ');

            for (int i = 0; i < 15; i++)
            {
                Players[i].Name = str[2 * i];
                Players[i].Score = Convert.ToInt32(str[2 * i + 1]);
            }
            sr.Close();
            fs.Close();
        }// считываем  таблицу рекордов

        public int record()
        {
            FileStream fs = new FileStream("rec.csv", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string str = sr.ReadToEnd();
            fs.Close();
            return str;
        }
        public void Read_FromFile(string name, int score)//Записываем и сравниваем результат
        {
            Read_record(record());

                for (int i = 0; i < 10; i++)
                {
                    Players[i].Name = str[2 * i];
                    Players[i].Score = Convert.ToInt32(str[2 * i + 1]);
                }

                for (int i = 0; i < 10; i++)
                {
                    if ((Players[i].Score < Players[10].Score) || (Players[i].Score == 0))
                    {
                        for (int j = i; j < 10 ; j++)
                        {
                            Players[j].Name = Players[j + 1].Name;
                            Players[j].Score = Players[j + 1].Score;
                        }

                        int u = i;
                        Players[u].Name = Players[10].Name;
                        Players[i].Score = Players[10].Score;
                        break;
                    }
                }
                sr.Close();
                fs.Close();

                StreamWriter sw = new StreamWriter("rec.txt", false);
                sw.WriteLine(Players[0].Name + " " + Players[0].Score.ToString());
                for (int i = 1; i < 10; i++)
                {
                    sw.WriteLine(" " + Players[i].Name + " " + Players[i].Score.ToString());
                }
                sw.Close();
            }
        

        public bool Check(int score)
        {
            
            Read_record();
            for (int i = 9; i < 0; i--)
            { if (Players[i].Score < score)
                return true;
 
            }

              return false;
 
        }
   }
    }
